//
//  TodayCustomerVC.m
//  AI
//
//  Created by zjhc on 2018/2/13.
//  Copyright © 2018年 zjhc. All rights reserved.
//

#import "TodayCustomerVC.h"
#import "CustomerInfoOneVC.h"
#import "TodayCustomerViewCell.h"
#import "CustomerModel.h"
#import <SDWebImage/UIButton+WebCache.h>
#import "TodayCustomerModel.h"
#import "UIColor+Extension.h"
#import "CustomerInfoTwoVC.h"
#import "AudioFileModel.h"
#import "DataBase.h"



@interface TodayCustomerVC ()<UITableViewDelegate,UITableViewDataSource> {
   

}
@property (weak, nonatomic) IBOutlet UITableView *tabview;
@property (strong,nonatomic) NSMutableArray *dataArray;

@end

@implementation TodayCustomerVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabview.delegate = self;
    self.tabview.dataSource = self;
    [self getRequestData];
    self.tabview.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    self.dataArray = [[NSMutableArray alloc] init];

    AudioFileModel *audioFileModel =[[AudioFileModel alloc]init];
    audioFileModel.isSuccess = NO;
    NSArray *failedList = [[DataBase sharedDataBase] getAudioFileByStatus:audioFileModel];
    CustomerInfoTwoVC *audioVC=[[CustomerInfoTwoVC alloc]init];
    
    for (int i = 0 ; i < failedList.count; i++) {
        [audioVC audioCommit:failedList[i]];
    }
    self.automaticallyAdjustsScrollViewInsets = false;
}

-(void)viewWillAppear:(BOOL)animated {
    [self getRequestData];
    self.tabBarController.tabBar.hidden = NO;
}

-(void)getRequestData{
    for (int i = 0; i < 5; i ++ ) {
       TodayCustomerModel *model  = [[TodayCustomerModel alloc]init];
        model.iconStr = @"http://img2.woyaogexing.com/2017/12/26/64c1913b6c511185!200x200.jpg";
        model.timeRange = @"01月10日  11:30-12:00";
        model.receptionStatus = arc4random()%2;
        model.receptioner = [NSString stringWithFormat:@"receptioner%d",i];
        [self.dataArray addObject:model];
    }
    [self.tabview reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return  self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TodayCustomerViewCell *todayCustomerCell = [tableView dequeueReusableCellWithIdentifier:@"TodayCustomerViewCell" forIndexPath:indexPath];
    
    TodayCustomerModel * model = [self.dataArray objectAtIndex:indexPath.row];

//    NSURL *url = [NSURL URLWithString:model.iconStr];
    [todayCustomerCell.avatar  setBackgroundImage:[UIImage imageNamed:@"头像测试"] forState:UIControlStateNormal];
    todayCustomerCell.avatar.layer.cornerRadius = todayCustomerCell.avatar.frame.size.width/2;
    todayCustomerCell.avatar.layer.masksToBounds = YES;
    todayCustomerCell.timeRange.text = model.timeRange;
    if (model.receptionStatus != 1) {
        todayCustomerCell.status.text =@"已接待";
        todayCustomerCell.name.text = @"王珞丹";
        todayCustomerCell.status.textColor =[UIColor colorWithHexString:@"455DAA"];
        todayCustomerCell.name.textColor =[UIColor colorWithHexString:@"455DAA"];

    } else {
        todayCustomerCell.status.text = @"未接待";
        todayCustomerCell.name.hidden = YES;
        todayCustomerCell.status.textColor = [UIColor colorWithHexString:@"F0553C"];
    }
    todayCustomerCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

    return todayCustomerCell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomerInfoOneVC *customerInfoOneVC = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomerInfoOneVC"];
    [self.navigationController pushViewController:customerInfoOneVC animated:YES];
}

@end
